//
//  SecondLaunchView.swift
//  网易新闻
//
//  Created by wl on 15/11/11.
//  Copyright © 2015年 wl. All rights reserved.
//  第二启动页面，使用xib
/***************************************************
*  如果您发现任何BUG,或者有更好的建议或者意见，请您的指教。
*邮箱:wxl19950606@163.com.感谢您的支持
***************************************************/
import UIKit

class SecondLaunchView: UIView, UIScrollViewDelegate {

    @IBOutlet weak var scrollView: UIScrollView!
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    struct Example {
        static let secondLaunchView = NSBundle.mainBundle().loadNibNamed("SecondLaunchView", owner: nil, options: nil).first as! SecondLaunchView
    }
    static func showAtWindow() {
        
        let window = UIApplication.sharedApplication().keyWindow
        Example.secondLaunchView.frame = window!.bounds
        window?.addSubview(Example.secondLaunchView)
        
        Example.secondLaunchView.scrollView.pagingEnabled = true
        Example.secondLaunchView.scrollView.showsHorizontalScrollIndicator = false

        Example.secondLaunchView.scrollView.pagingEnabled = true
        Example.secondLaunchView.scrollView.contentSize = CGSize(width: Example.secondLaunchView.frame.size.width * 4, height: Example.secondLaunchView.frame.size.height)
       
        let frame = Example.secondLaunchView.bounds
        
        for i in 0..<4{
           
            let imgfile = "guide\(Int(i+1)).png"
            print(imgfile)
            let view = UIView(frame: CGRect(x: (SCREEN_WIDTH * CGFloat(i)), y: 0.0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT))
            let image = UIImage(named: imgfile)!
            let imageview = UIImageView(frame: frame)
            imageview.contentMode = UIViewContentMode.ScaleToFill
            imageview.image = image
            view.addSubview(imageview)
            Example.secondLaunchView.scrollView.addSubview(view)
            if i == 3{
                let enterButton = UIButton(frame: CGRect(x: 0, y: 0, width: 160, height: 38))
                var frame = enterButton.frame
                frame.origin.x = (SCREEN_WIDTH - 160) / 2
                frame.origin.y = SCREEN_HEIGHT - 38 - 40
                enterButton.frame = frame
                enterButton.setTitle("立即进入", forState: UIControlState.Normal)
                enterButton.backgroundColor = UIColor.blackColor()
                
                enterButton.layer.cornerRadius = 5
                enterButton.addTarget(self, action: #selector(SecondLaunchView.pressEnterButton), forControlEvents: UIControlEvents.TouchUpInside)
               
                view.addSubview(enterButton)
                
            }

            
        }
        
    }
   static func pressEnterButton(){
          print("yincang")
    
         Example.secondLaunchView.removeFromSuperview()
    
    }
    
}



// 版权属于原作者
// http://code4app.com (cn) http://code4app.net (en)
// 发布代码于最专业的源码分享网站: Code4App.com